using System;
using System.Windows.Forms;
using System.Drawing;

namespace HIS
{
    public class LoginForm : Form
    {
        private TextBox txtUsername;
        private TextBox txtPassword;
        private Button btnLogin;
        private Label lblUsername;
        private Label lblPassword;
        private Label lblTitle;

        public LoginForm()
        {
            InitializeComponents();
        }

        private void InitializeComponents()
        {
            // 窗体设置
            this.Text = "医院信息系统 - 登录";
            this.Size = new Size(400, 300);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;

            // 标题标签
            lblTitle = new Label
            {
                Text = "医院信息系统",
                Font = new Font("微软雅黑", 16, FontStyle.Bold),
                AutoSize = true,
                Location = new Point(120, 30)
            };

            // 用户名标签
            lblUsername = new Label
            {
                Text = "用户名：",
                AutoSize = true,
                Location = new Point(50, 90)
            };

            // 用户名输入框
            txtUsername = new TextBox
            {
                Location = new Point(120, 87),
                Size = new Size(200, 25)
            };

            // 密码标签
            lblPassword = new Label
            {
                Text = "密码：",
                AutoSize = true,
                Location = new Point(50, 130)
            };

            // 密码输入框
            txtPassword = new TextBox
            {
                Location = new Point(120, 127),
                Size = new Size(200, 25),
                PasswordChar = '*'
            };

            // 登录按钮
            btnLogin = new Button
            {
                Text = "登录",
                Location = new Point(150, 180),
                Size = new Size(100, 30)
            };
            btnLogin.Click += BtnLogin_Click;

            // 添加控件到窗体
            this.Controls.AddRange(new Control[] {
                lblTitle,
                lblUsername,
                txtUsername,
                lblPassword,
                txtPassword,
                btnLogin
            });
        }

        private void BtnLogin_Click(object sender, EventArgs e)
        {
            // 简单的账号密码验证
            if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text))
            {
                MessageBox.Show("请输入用户名和密码！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // 测试账号：admin
            // 测试密码：123456
            if (txtUsername.Text == "admin" && txtPassword.Text == "123456")
            {
                MainForm mainForm = new MainForm();
                mainForm.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("用户名或密码错误！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
} 